package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.d_c.model.Role;
import com.zr.d_c.service.FuncService;
import com.zr.d_c.service.RoleService;
import com.zr.d_c.serviceimpl.FuncServiceImpl;
import com.zr.d_c.serviceimpl.RoleServiceImpl;
/**
 * 展示所有功能
 * @author Administrator
 *
 */
public class ShowAllFuncsController extends HttpServlet {

	RoleService roleservice = new RoleServiceImpl();
	FuncService funcservice = new FuncServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String rolename = req.getParameter("rolename");
		Role r = roleservice.getRoleByRname(rolename);
		PrintWriter pw = resp.getWriter();
		if(r==null){
			pw.write(funcservice.getAllFuncsByPartentId(-1).toString());
		}else{
			pw.write(funcservice.getAllFuncsByPartentId(-1, r.getRid()).toString());
		}
		pw.close();
	}
}
